package cn.kent;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 思路:先转成分钟，然后比较
 */
public class FindMinDifference {
    // 先转成分钟，然后比较
    public static int findMinDifference(List<String> timePoints) {
        int n = timePoints.size();
        if (n > 1440) {
            return 0;
        }
        Collections.sort(timePoints);
        int ans = Integer.MAX_VALUE;
        int t0Minutes = getMinutes(timePoints.get(0));
        int preMinutes = t0Minutes;
        for (int i = 1; i < n; ++i) {
            int minutes = getMinutes(timePoints.get(i));
            ans = Math.min(ans, minutes - preMinutes); // 相邻时间的时间差
            preMinutes = minutes;
        }
        ans = Math.min(ans, t0Minutes + 1440 - preMinutes); // 首尾时间的时间差
        return ans;
    }

    public static int getMinutes(String t) {
        return ((t.charAt(0) - '0') * 10 + (t.charAt(1) - '0')) * 60 + (t.charAt(3) - '0') * 10 + (t.charAt(4) - '0');
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        // list.add("12:12");
        // list.add("00:13");

        // list.add("00:00");
        // list.add("00:00");
        // list.add("23:59"); // 0

        list.add("05:31"); // 5*60+31 = 331
        list.add("22:08"); // 22*60+8 = 1328
        list.add("00:35"); // 35    147
        int minDifference = findMinDifference(list);
        System.out.println(minDifference);
    }
}
